<template>
	<view class="page">
		<!-- 搜索框 -->
		<view class="article-search">
			<view class="search">
				<view class="location" @click="getLocation">
					<view class="iconfont icon-dingwei"></view> <!-- 这里可以换成定位图标 -->
				</view>
				<input type="text" placeholder="输入搜索内容" v-model="queryList.name" @confirm="onSearch" />
				<view class="search-button" @click="onSearch">搜索</view>
			</view>
			<view class="shop" @click="Settled">
				我要入驻
			</view>
		</view>
		<view class="markList">
			<view class="markItem" v-for="item in markList" @click="markAdress(item)">
				<image :src="item.avatar_img||item.logo_img"></image <view class="title1">

				<view class="title1">
					{{item.store_name}} </view>
				<view class="title2">
					{{item.introduce}}
				</view>
			</view>

		</view>
	</view>
	</view>
</template>

<script>
	import {
		getPainterList
	} from '@/config/api.js';
	export default {
		data() {
			return {
				queryList:{
					navId: null,
					page: 1,
					name:'',
					limit: 20
				},
				markList: [],
				searchQuery: '', // 存储搜索内容
				location: '', // 存储位置信息
			};
		},
		onLoad(options) {
			// 获取传递的标题
			if (options.title) {
				this.title = decodeURIComponent(options.title); // 解码并设置标题
				uni.setNavigationBarTitle({
					title: this.title // 设置导航栏标题
				});
				this.queryList.navId = options.id;
				this.markListById();
			}
		},
		methods: {
			markListById(){
				getPainterList(this.queryList).then(res => {
					this.markList = res.data;
				})
			},
			//每个商户详情
			markAdress(item) {
				if(this.queryList.navId == 11){
					return uni.navigateTo({
						url: `/moduleA/storeList/auctionOmpany?title=${encodeURIComponent(item.store_name)}&storeId=${item.id}&navId=${this.queryList.navId}`,
					});
				}
				return uni.navigateTo({
					url: `/moduleA/storeList/appraiser?title=${encodeURIComponent(item.store_name)}&storeId=${item.id}&navId=${this.queryList.navId}`,
				});
			},
			// 获取用户定位
			getLocation() {
				uni.getLocation({
					type: 'wgs84',
					success: (res) => {
						this.location = `${res.latitude}, ${res.longitude}`; // 存储经纬度
						uni.showToast({
							title: '定位成功',
							icon: 'success',
						});
						console.log('用户定位:', this.location);
					},
					fail: (err) => {
						uni.showToast({
							title: '获取定位失败',
							icon: 'none',
						});
						console.error(err);
					},
				});
			},
			// 执行搜索
			onSearch() {
				this.markListById();
			},
			// 我要入驻的点击事件
			Settled() {
				let title = "评估机构"
				const navId = this.queryList.navId;
				let url =  `/moduleA/MerchantIn/pingGujianDing/pingGujianDing`;
				if(navId == 10){
					title = '鉴定师'
					url =  `/moduleA/MerchantIn/jianDingShi/jianDingShi`;
				}if(navId == 11){
					title = '拍卖公司'
					url =  `/moduleA/MerchantIn/paiMaiGongSi/paiMaiGongSi`;
				}
				uni.navigateTo({
					url:url+`?title=${encodeURIComponent(title)}&nav_id=${navId}`, // 请替换为实际路径`
				});
			},
		},
	};
</script>



<style scoped lang="scss">
	@import 'markList.scss';
</style>